package com.zhang.controller;

import com.github.pagehelper.PageInfo;
import com.zhang.pojo.ChannelBean;
import com.zhang.pojo.MainBean;
import com.zhang.pojo.UserBean;
import com.zhang.service.IMainService;
import jdk.tools.jaotc.Main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("main")
public class MainController {
    @Autowired
    private IMainService mainService;

    @RequestMapping("findByChannelId")
    public PageInfo<MainBean> findByChannelId(int pageNo, int channelId, String name, String author, LocalDate start, LocalDate end){
        return mainService.findByChannelId(pageNo, channelId, name, author, start, end);
    }

    @RequestMapping("add")
    public String add(MainBean mainBean,int channelId, HttpServletRequest req){
        UserBean userBean = (UserBean) req.getSession().getAttribute("userBean");
        mainService.addMain(mainBean,userBean.getUserId(),channelId);
        return "ok";
    }

    @RequestMapping("findById")
    public MainBean findById(int id){
       return mainService.findById(id);
    }

}
